package com.asistencia.businness;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.asistencia.dao.interfaces.ScheduleDao;
import com.asistencia.domain.Schedule;
@Service
public class ScheduleBusiness {
	
	@Autowired
	private ScheduleDao scheduleDao;
	
	@Autowired
	private Schedule schedule;
	
	public int updateScheduleById(String state, Integer idSchedule){
		schedule.setIdSchedule(idSchedule);
		schedule.setState(state);
		return scheduleDao.updateById(schedule);
	}
	
	public List<Schedule> listByCourseSemester(Integer idCourse, Integer idSemester){
		try{
			scheduleDao.listByCourseSemester(idCourse, idSemester);
			List<Schedule> lstByCour=scheduleDao.listByCourseSemester(idCourse, idSemester);
			return lstByCour;
		}catch (DataAccessException e){
			e.printStackTrace();
			return null;
			} catch(Exception e){
				e.printStackTrace();
				return null;
			}
			}
	
	public List<Schedule> listByClassroomSemester(Integer idClassroom, Integer idSemester) {
		try{
			scheduleDao.listByClassroomSemester(idClassroom, idSemester);
			List<Schedule> lstByClass=scheduleDao.listByClassroomSemester(idClassroom, idSemester);
			return lstByClass;
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} catch(Exception e){
			e.printStackTrace();
			return null;
		}
		}
	
	public Schedule getById(Integer idSchedule){
		try{
			schedule=scheduleDao.getById(idSchedule);
			return schedule;
		}catch (DataAccessException e){
			e.printStackTrace();
			return null;
		}
			
			
		}
		
}
